//
//  StopToStopDetailViewController.m
//  Bus_iPhone
//
//  Created by 修勇 黄 on 12-7-15.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "StopToStopDetailViewController.h"

@interface StopToStopDetailViewController ()

@end

@implementation StopToStopDetailViewController

@synthesize dataDic=_dataDic;

@synthesize startStopArray=_startStopArray;
@synthesize endStopArray=_endStopArray;

-(void)dealloc{

    [_dataDic release];
    [super dealloc];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setCustomNavigationReturnItem];
   
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


#pragma mark -UITableViewDataSource And Delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (section) {
        case 0:
            return _startStopArray.count;
            break;
        case 1:
            return [[_dataDic objectForKey:@"sameStop"]count];
            break;
        case 2:
            return _endStopArray.count;
            break;
        default:
            return 0;
            break;
    }
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    switch (section) {
        case 0:
        {
            NSDictionary *tempStartDic=[_dataDic objectForKey:@"startLineInfo"];
            return [NSString stringWithFormat:@"先乘坐 %@",[tempStartDic objectForKey:@"lineName"]];
        }
            break;
        case 1:
            return @"可以在以下车站换乘:";
            break;
        case 2:
        {
            NSDictionary *tempEndDic=[_dataDic objectForKey:@"endLineInfo"];
            return [NSString stringWithFormat:@"然后乘坐 %@",[tempEndDic objectForKey:@"lineName"]];
        }
        default:
            return nil;
            break;
    }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellStrig=@"stop to stop detail";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellStrig];
    if (!cell) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStrig] autorelease];
    }
    NSDictionary *dic=nil;
    switch (indexPath.section) {
        case 0:
            dic=[_startStopArray objectAtIndex:indexPath.row];
            break;
        case 1:
            dic=[[_dataDic objectForKey:@"sameStop"] objectAtIndex:indexPath.row];
            break;
        case 2:
            dic=[_endStopArray objectAtIndex:indexPath.row];
            break;
        default:
            break;
    }
    cell.indentationLevel=2;
    cell.textLabel.text=[dic objectForKey:@"stopName"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSDictionary *dic=nil;
    switch (indexPath.section) {
        case 0:
            dic=[_startStopArray objectAtIndex:indexPath.row];
            break;
        case 1:
            dic=[[_dataDic objectForKey:@"sameStop"] objectAtIndex:indexPath.row];
            break;
        case 2:
            dic=[_endStopArray objectAtIndex:indexPath.row];
            break;
        default:
            break;
    }
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ShowBusStopDetailNotication" object:dic];
}
@end
